#!/usr/bin/env python

import socket
import struct
import sys

if len(sys.argv) != 2:
	print "Usage: %s int_ip|str_ip" % sys.argv[0]
	sys.exit(0)

try:
	int_ip = int(sys.argv[1])
	#print "convert to string"
	if int_ip < 0: # convert to unsigned long first
		int_ip = struct.unpack('I', struct.pack('i', int_ip))[0]
	print socket.inet_ntoa(struct.pack('I',socket.htonl(int_ip))) 

except ValueError:
	#print "convert from string"
	uint = socket.ntohl(struct.unpack("I",socket.inet_aton(str(sys.argv[1])))[0]) 
	print uint
	if uint >= 2147483648:
		print struct.unpack('i', struct.pack('I', uint))[0]
